if (window.WEIBW == null) {
  window.WEIBW = {};
}
WEIBW.author = "weibw(韦博文)[weibw162]<weibw162@163.com>";
WEIBW.version = "0.0.3";


(function (jq) {
  jq.extend(WEIBW, {
    _isNull: function (v) {
      /**
       * 判断当前对象是否为空
       */
      return v == undefined || v == null
    },
    _isExist: function (o) {
      /**
       * 判断当前对象是否存在
       */
      if (typeof (o) == typeof (jq())) {
        return o.length > 0;
      }
    },
    _hasProperty: function (o, k, d) {
      /**
       * 判断对象o是否有属性k，如果有则返回该属性，没有则返回默认值d，如果未传入默认值则返回false
       */
      return o.hasOwnProperty(k) ? o[k] : (d || false);
    },
    _randomId: function (l) {
      /**
       * 根据传入参数l生成一个长度为l的随机字符串
       */
      len = l || 8;
      const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
      const maxPos = $chars.length;
      let id = '';
      for (let i = 0; i < len; i++) {
        id += $chars.charAt(Math.floor(Math.random() * maxPos));
      }
      return id;
    },
    _num2px: function (n) {
      /**
       * 数字转像素字符串
       */
      return n + "px";
    },

    _px2num: function (n) {
      /**
       * 像素字符串转数字
       */
      return parseInt(n, 10);
    },
    _assembleElements: function (o) {
      /**
       * 组装元素
       */
      if (o.node) {
        o.pchild?.forEach((e, i) => {
          WEIBW._assembleElements(e);
          o.node.prepend(e.node);
        })
        o.achild?.forEach((e, i) => {
          WEIBW._assembleElements(e);
          o.node.append(e.node);
        })

      }
    }
  })
})(jQuery);

// 定义ICON 图片的SVG
(function (jq) {
  jq.extend(WEIBW, {
    ICON: function () {
      return {
        success: '<svg viewBox="0 0 1024 1024"xmlns="http://www.w3.org/2000/svg"><path fill="currentColor"d="M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm-55.808 536.384-99.52-99.584a38.4 38.4 0 1 0-54.336 54.336l126.72 126.72a38.272 38.272 0 0 0 54.336 0l262.4-262.464a38.4 38.4 0 1 0-54.272-54.336L456.192 600.384z"></path></svg>',
        warning: '<svg viewBox="0 0 1024 1024"xmlns="http://www.w3.org/2000/svg"><path fill="currentColor"d="M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 192a58.432 58.432 0 0 0-58.24 63.744l23.36 256.384a35.072 35.072 0 0 0 69.76 0l23.296-256.384A58.432 58.432 0 0 0 512 256zm0 512a51.2 51.2 0 1 0 0-102.4 51.2 51.2 0 0 0 0 102.4z"></path></svg>',
        info: '<svg viewBox="0 0 1024 1024"xmlns="http://www.w3.org/2000/svg"><path fill="currentColor"d="M512 64a448 448 0 1 1 0 896.064A448 448 0 0 1 512 64zm67.2 275.072c33.28 0 60.288-23.104 60.288-57.344s-27.072-57.344-60.288-57.344c-33.28 0-60.16 23.104-60.16 57.344s26.88 57.344 60.16 57.344zM590.912 699.2c0-6.848 2.368-24.64 1.024-34.752l-52.608 60.544c-10.88 11.456-24.512 19.392-30.912 17.28a12.992 12.992 0 0 1-8.256-14.72l87.68-276.992c7.168-35.136-12.544-67.2-54.336-71.296-44.096 0-108.992 44.736-148.48 101.504 0 6.784-1.28 23.68.064 33.792l52.544-60.608c10.88-11.328 23.552-19.328 29.952-17.152a12.8 12.8 0 0 1 7.808 16.128L388.48 728.576c-10.048 32.256 8.96 63.872 55.04 71.04 67.84 0 107.904-43.648 147.456-100.416z"></path></svg>',
        error: '<svg viewBox="0 0 1024 1024"xmlns="http://www.w3.org/2000/svg"><path fill="currentColor"d="M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 393.664L407.936 353.6a38.4 38.4 0 1 0-54.336 54.336L457.664 512 353.6 616.064a38.4 38.4 0 1 0 54.336 54.336L512 566.336 616.064 670.4a38.4 38.4 0 1 0 54.336-54.336L566.336 512 670.4 407.936a38.4 38.4 0 1 0-54.336-54.336L512 457.664z"></path></svg>',
        close: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path fill = "currentColor" d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z" ></path></svg >',
      }
    }()
  })
})(jQuery);

(function (jq) {
  jq.extend(WEIBW, {
    throw: function (e) {
      return console.error(e);
    },
    ERROR: function () {
      return {
        E10001: function (e) {
          return e + "函数参数未传递！"
        }
      }
    }()
  })
})(jQuery);


// (function (jq) {
//   jq.extend(WEIBW, {
//     FORM: function () {
//       return {
//         form: function (o) {
//           return jq("<form></form>");
//         }
//       }
//     }()
//   })
// })(jQuery);

(function (jq) {

  jq.extend(WEIBW, {
    Feedback: function () {
      return {
        alert: function (o) {
          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.alert()"));
            return;
          }
          // 将目前已存在的alert元素删除掉
          jq("#wei-feedback-alert").remove();
          const title = WEIBW._hasProperty(o, "title") || "默认title，如果看到此文本表示你的title未定义";
          const type = WEIBW._hasProperty(o, "type") || "info";
          const effect = "is-" + (WEIBW._hasProperty(o, "effect") || "light");
          const description = WEIBW._hasProperty(o, "description");
          const width = WEIBW._hasProperty(o, "width") || "40%";
          const center = WEIBW._hasProperty(o, "center");
          const closeText = WEIBW._hasProperty(o, "closeText");
          const showIcon = WEIBW._hasProperty(o, "showIcon");
          const callback = WEIBW._hasProperty(o, "callback");
          const offset = WEIBW._hasProperty(o, "offset") || "10px";

          const $dv = jq("<div id='wei-feedback-alert'></div>").addClass("wei-alert").addClass("wei-alert--" + type).addClass(effect).css({ width: width });
          const $alert_content = jq("<div></div>").addClass("wei-alert__content");
          const $alert_title = jq("<span>" + title + "</span>").addClass("wei-alert__title");
          // 内容居中
          if (center) {
            $dv.addClass("is-center");
          }
          // 距离顶部的偏移
          if (offset) {
            $dv.css({ top: offset });
          }

          const top = parseInt($dv.css('top'), 10);
          $dv.css({ top: WEIBW._num2px(top - 80) });

          // 图标
          if (showIcon) {
            const $alert_content_icon = jq("<i></i>").addClass("wei-icon wei-alert__icon");
            const $alert_content_icon_svg = jq(WEIBW.ICON[type] || WEIBW.ICON.info);
            if (description) {
              $alert_content_icon.addClass("is-big");
            }
            WEIBW._assembleElements({
              node: $dv,
              achild: [
                {
                  node: $alert_content_icon,
                  achild: [
                    { node: $alert_content_icon_svg }
                  ]
                }
              ]
            })
          }

          // 描述
          if (description) {
            $alert_title.addClass("is-bold")
            const $alert_description = jq("<p>" + description + "</p>");
            $alert_description.appendTo($alert_content);
          }

          // 关闭按钮
          let $alert_close_btn = null;
          if (closeText) {
            $alert_close_btn = jq("<div>" + closeText + "</div>").addClass("wei-alert__close-btn is-customed");
          } else {
            $alert_close_btn = jq("<i><i/>").addClass("wei-icon wei-alert__close-btn");
            const $alert_close_btn_icon = jq(WEIBW.ICON.close);
            $alert_close_btn_icon.appendTo($alert_close_btn);
          }

          $alert_close_btn.click(() => {
            $dv.animate({
              "opacity": 0,
              "top": WEIBW._num2px(top + 30)
            }, 100, 'linear', () => {
              $dv.remove();
              if (callback) {
                callback();
              }
            });
          });

          WEIBW._assembleElements({
            node: $dv,
            achild: [
              {
                node: $alert_content,
                pchild: [
                  { node: $alert_title }
                ],
                achild: [
                  { node: $alert_close_btn }
                ]
              }
            ]
          })

          $dv.appendTo(jq("body")).animate({ "opacity": 1, top: WEIBW._num2px(top) }, 200);
        },

        notification: function (o) {
          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.notification()"));
            return;
          }

          const title = WEIBW._hasProperty(o, "title") || "默认title";
          const message = WEIBW._hasProperty(o, "message") || "";
          const type = WEIBW._hasProperty(o, "type") || "";
          const duration = WEIBW._hasProperty(o, "duration") || 4500;
          const showClose = WEIBW._hasProperty(o, "showClose");
          const callback = WEIBW._hasProperty(o, "callback");
          const position = WEIBW._hasProperty(o, "position") || "right-top";
          const useHTML = WEIBW._hasProperty(o, "useHTML") || false;

          // 拆分元素位置字符串
          const [positionX, positionY] = position.split("-");
          const idStr = "wei_notification_" + position.replace("-", "_") + "_";
          const id = idStr + WEIBW._randomId(8);
          let positionOffset = 16;
          // 计算当前notifaction的位置
          jq("div[id^='" + idStr + "']").each((i, el) => { positionOffset += parseInt(jq(el).outerHeight(), 10) + 16 });
          const positionStyle = { [positionY]: WEIBW._num2px(positionOffset), [positionX]: "-330px" };
          const positionShowStyle = { [positionX]: "26px" };

          // 定义基础结构
          const $dv = jq("<div id='" + id + "'></div>").addClass("wei-notification").addClass(positionX).css({ "z-index": 2000, ...positionStyle });
          const $notification_group = jq("<div></div>").addClass("wei-notification__group");
          const $notification_title = jq("<h2>" + title + "</h2>").addClass("wei-notification__title");
          const $notification_content = jq("<div>" + (useHTML ? message : "<p>" + message + "</p>") + "</div>").addClass("wei-notification__content");

          // 类型
          if (type !== "") {
            const $notification__icon_svg = jq(WEIBW.ICON[type] || WEIBW.ICON.info);;
            const $notification__icon = jq("<i><i/>").addClass("wei-icon wei-notification__icon").addClass("wei-notification--" + type);
            WEIBW._assembleElements({
              node: $dv,
              achild: [
                {
                  node: $notification__icon,
                  achild: [
                    { node: $notification__icon_svg }
                  ]
                }
              ]
            })
          }

          // 关闭按钮
          if (showClose) {
            const $notification_closeBtn = jq("<i><i/>").addClass("wei-icon wei-notification__closeBtn");
            const $notification__closeBtn_icon = jq(WEIBW.ICON.close);
            $notification_closeBtn.click(() => { removeDv(); })
            WEIBW._assembleElements({
              node: $notification_group,
              achild: [
                {
                  node: $notification_closeBtn,
                  achild: [
                    { node: $notification__closeBtn_icon }
                  ]
                }
              ]
            })
          }

          // 移除元素
          const removeDv = function () {
            $dv.animate({
              "opacity": 0,
              [positionX]: "-330px"
            }, 50, 'linear', () => {
              const height = parseInt($dv.outerHeight(), 10) + 16;
              const id = $dv.attr("id");
              let notificationList = jq("div[id^='" + idStr + "']");
              let index = 0;
              notificationList.each((i, el) => {
                if (jq(el).attr("id") == id) {
                  index = i;
                  return false;
                }
              });
              $dv.remove();
              notificationList.slice(index).each((i, el) => {
                if (jq(el).attr("id") != id) {
                  jq(el).css({ [positionY]: parseInt(jq(el).css(positionY), 10) - height })
                }
              });
              if (callback) {
                callback();
              }

            });
          }

          // 组装元素
          WEIBW._assembleElements({
            node: $dv,
            achild: [
              {
                node: $notification_group,
                achild: [
                  { node: $notification_title },
                  { node: $notification_content }
                ]
              }
            ]
          })

          $dv.appendTo(jq("body")).animate({ opacity: 1, ...positionShowStyle }, 20);

          setTimeout(function () {
            if (WEIBW._isExist(jq("<div id='" + id + "'></div>"))) { removeDv(); }
          }, duration);


        },

        message: function (o) {
          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.message()"));
            return;
          }
          const message = WEIBW._hasProperty(o, "message") || "默认Message";
          const type = WEIBW._hasProperty(o, "type") || "info";
          const duration = WEIBW._hasProperty(o, "duration") || 4500;
          const showClose = WEIBW._hasProperty(o, "showClose");
          const center = WEIBW._hasProperty(o, "center", true);
          const callback = WEIBW._hasProperty(o, "callback");
          let offset = WEIBW._hasProperty(o, "offset") || 10;



          const idStr = "wei_message_";
          const id = idStr + WEIBW._randomId(8);

          jq("div[id^='" + idStr + "']").each((i, el) => { offset += parseInt(jq(el).outerHeight(), 10) + 16 });
          const $dv = jq("<div id='" + id + "'></div>").addClass("wei-message").addClass("wei-message--" + type).css({ "z-index": 2000, "top": WEIBW._num2px(offset - 80) });;
          const $message__icon_svg = jq(WEIBW.ICON[type] || WEIBW.ICON.info);;
          const $message__icon = jq("<i><i/>").addClass("wei-icon wei-message__icon").addClass("wei-message-icon--" + type);


          const $message_content = $("<p >" + message + "</p>").addClass("wei-message__content");

          WEIBW._assembleElements({
            node: $dv,
            achild: [
              {
                node: $message__icon,
                achild: [
                  { node: $message__icon_svg }
                ]
              },
              { node: $message_content }
            ]
          })


          // 内容居中
          if (center) {
            $dv.addClass("is-center");
          }

          // 关闭按钮
          if (showClose) {

            $dv.addClass("is-closable");
            const $message_closeBtn = jq("<i><i/>").addClass("wei-icon wei-message__closeBtn");
            const $message__closeBtn_icon = jq(WEIBW.ICON.close);
            $message__closeBtn_icon.appendTo($message_closeBtn);
            $message_closeBtn.appendTo($dv).click(() => { removeDv(); })
          }

          // 移除元素
          const removeDv = function () {
            const height = parseInt($dv.outerHeight(), 10) + 16;
            const id = $dv.attr("id");
            let messageList = jq("div[id^='" + idStr + "']");
            let index = 0;
            $dv.animate({
              "opacity": 0,
              top: parseInt($dv.css("top"), 10)
            }, 50, 'linear', () => {
              messageList.each((i, el) => {
                if (jq(el).attr("id") == id) {
                  index = i;
                  return false;
                }
              });
              $dv.remove();
              messageList.slice(index).each((i, el) => {
                if (jq(el).attr("id") != id) {
                  jq(el).css({ top: parseInt(jq(el).css("top"), 10) - height })
                }
              });
              if (callback) {
                callback();
              }
            });
          }

          $dv.appendTo(jq("body")).animate({ "opacity": 1, top: WEIBW._num2px(offset) }, 200, "linear");
          // 定时关闭
          setTimeout(function () {
            if (WEIBW._isExist(jq("<div id='" + id + "'></div>"))) { removeDv(); }
          }, duration);
        },


        closeConfirm: function (bf, af) {
          /**
           * 关闭confirm窗口
           * bf，前置事件
           * af，后置事件
           */
          if (bf) { bf() };
          jq("div[id^='wei_messageBox_confirm_']").animate({
            "opacity": 0,
          }, 100, 'linear', () => {
            jq("div[id^='wei_messageBox_confirm_']").remove();
            if (af) { af() };
          });

        },

        confirm: function (o) {
          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.confirm()"));
            return;
          }

          const title = WEIBW._hasProperty(o, "title") || "默认title";
          const message = WEIBW._hasProperty(o, "message") || "默认Message";
          const type = WEIBW._hasProperty(o, "type") || false;
          const confirm = WEIBW._hasProperty(o, "confirm") || {};
          const cancel = WEIBW._hasProperty(o, "cancel") || {};
          const custombtns = WEIBW._hasProperty(o, "custombtns") || [];
          const center = WEIBW._hasProperty(o, "center") || false;


          const idStr = "wei_messageBox_confirm_";
          const id = idStr + WEIBW._randomId(8);

          // 先移除现有的窗口
          jq("div[id^='wei_messageBox_confirm_']").remove();

          // 定义基础结构
          const $dv = jq("<div id='" + id + "'></div>").addClass("wei-overlay is-message-box");
          const $overlayMessageBox = jq("<div></div>").addClass("wei-overlay-message-box");
          const $messageBox = jq("<div></div>").addClass("wei-message-box");
          const $messageBox_header = jq("<div></div>").addClass("wei-message-box__header");
          const $messageBox_content = jq("<div></div>").addClass("wei-message-box__content");
          const $messageBox_btns = jq("<div></div>").addClass("wei-message-box__btns");

          // title
          const $messageBox_title = jq("<div><span>" + title + "</span></div>").addClass("wei-message-box__title");
          const $messageBox_headerbtn = jq("<button type='button'></button>").addClass("wei-message-box__headerbtn").click(() => { $dv.remove(); });;
          const $messageBox_headerbtn_close = jq("<i><i/>").addClass("wei-icon wei-message-box__close");
          const $messageBox__headerbtn_close_icon = jq(WEIBW.ICON.close);


          const $messageBox_content_container = jq("<div></div>").addClass("wei-message-box__container");

          // 图标
          if (type) {
            const $messageBox_content_status = jq("<i><i/>").addClass("wei-icon wei-message-box__status wei-message-box-icon--" + type);
            const $messageBox_content_status_icon = jq(WEIBW.ICON[type]);
            $messageBox_content_status_icon.appendTo($messageBox_content_status);
            if (center) {
              // 如果居中，要将图表插入到标题节点
              $messageBox_content_status.prependTo($messageBox_title);
            } else {
              $messageBox_content_status.appendTo($messageBox_content_container);
            }

          }

          // 主要内容
          const $messageBox_content_message = jq("<div><p>" + message + "</p></div>").addClass("wei-message-box__message");

          // 内容居中
          if (center) {
            $messageBox.addClass("wei-message-box--center");
          }

          // 确认按钮
          if (WEIBW._hasProperty(confirm, "show", true)) {
            const $messageBox_btns_confirm = jq("<button type='button' ><span>" + WEIBW._hasProperty(confirm, "text", "确认") + "</span></button>").addClass("wei-button wei-button--" + WEIBW._hasProperty(confirm, "type", "primary"))
            $messageBox_btns_confirm.click(() => {
              // 点击后首先设置按钮不可用，避免重复点击
              $messageBox_btns_confirm.attr('disabled', "true").addClass("is-disabled");
              // 如果有自定义事件，则执行自定义事件，否则默认是关闭窗口
              WEIBW._hasProperty(confirm, "clickfunc", false) ? confirm["clickfunc"]() : WEIBW.Feedback.closeConfirm(() => {
                $messageBox_btns_confirm.removeAttr("disabled").removeClass("is-disabled");
              });
            });
            $messageBox_btns_confirm.appendTo($messageBox_btns);
          }

          // 取消按钮
          if (WEIBW._hasProperty(cancel, "show", false)) {
            const $messageBox_btns_cancel = jq("<button type='button' ><span>" + WEIBW._hasProperty(cancel, "text", "取消") + "</span></button>").addClass("wei-button wei-button--" + WEIBW._hasProperty(cancel, "type", "plain"))
            $messageBox_btns_cancel.click(() => {
              // 点击后首先设置按钮不可用，避免重复点击
              $messageBox_btns_cancel.attr('disabled', "true").addClass("is-disabled");
              // 如果有自定义事件，则执行自定义事件，否则默认是关闭窗口
              WEIBW._hasProperty(cancel, "clickfunc", false) ? cancel["clickfunc"]() : WEIBW.Feedback.closeConfirm(() => {
                $messageBox_btns_cancel.removeAttr("disabled").removeClass("is-disabled");
              });;
            });
            $messageBox_btns_cancel.appendTo($messageBox_btns);
          }

          // 自定义按钮
          if (custombtns.length > 0) {
            custombtns.forEach(v => {
              const $messageBox_btns_custom = jq("<button type='button' ><span>" + WEIBW._hasProperty(v, "text", "自定义") + "</span></button>").addClass("wei-button wei-button--" + WEIBW._hasProperty(v, "type", "primary"));
              $messageBox_btns_custom.click(() => {
                // 点击后首先设置按钮不可用，避免重复点击
                $messageBox_btns_custom.attr('disabled', "true").addClass("is-disabled");
                // 如果有自定义事件，则执行自定义事件，否则默认是关闭窗口
                WEIBW._hasProperty(v, "clickfunc", false) ? v["clickfunc"]() : WEIBW.Feedback.closeConfirm(() => {
                  $messageBox_btns_custom.removeAttr("disabled").removeClass("is-disabled");
                });;
              });
              $messageBox_btns_custom.appendTo($messageBox_btns);
            })
          }


          // 组装元素
          WEIBW._assembleElements({
            node: jq("body"),
            achild: [
              {
                node: $dv,
                achild: [
                  {
                    node: $overlayMessageBox,
                    achild: [
                      {
                        node: $messageBox,
                        achild: [
                          {
                            node: $messageBox_header,
                            achild: [
                              { node: $messageBox_title },
                              {
                                node: $messageBox_headerbtn,
                                achild: [
                                  {
                                    node: $messageBox_headerbtn_close,
                                    achild: [
                                      { node: $messageBox__headerbtn_close_icon }
                                    ]
                                  }
                                ]
                              }
                            ]
                          },
                          {
                            node: $messageBox_content,
                            achild: [
                              {
                                node: $messageBox_content_container,
                                achild: [
                                  { node: $messageBox_content_message }
                                ]
                              }
                            ]
                          },
                          { node: $messageBox_btns }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          })
        },

        closePrompt: function (bf, af) {
          /**
           * 关闭prompt窗口
           * bf，前置事件
           * af，后置事件
           */
          if (bf) { bf() };
          jq("div[id^='wei_messageBox_prompt_']").animate({
            "opacity": 0,
          }, 100, 'linear', () => {
            jq("div[id^='wei_messageBox_prompt_']").remove();
            if (af) { af() };
          });

        },

        prompt: function (o) {
          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.prompt()"));
            return;
          }

          const title = WEIBW._hasProperty(o, "title") || "默认title";
          const label = WEIBW._hasProperty(o, "label") || "默认label";
          const type = WEIBW._hasProperty(o, "type") || false;
          const rule = WEIBW._hasProperty(o, "rule") || "";
          const errormsg = WEIBW._hasProperty(o, "errormsg") || "请填入正确值！";
          const submit = WEIBW._hasProperty(o, "submit") || {};
          const cancel = WEIBW._hasProperty(o, "cancel") || {};
          const custombtns = WEIBW._hasProperty(o, "custombtns") || [];


          const idStr = "wei_messageBox_prompt_";
          const id = idStr + WEIBW._randomId(8);
          const iputId = idStr + WEIBW._randomId(8);

          // 先移除现有的窗口
          jq("div[id^='wei_messageBox_prompt_']").remove();

          // 定义基础结构
          const $dv = jq("<div id='" + id + "'></div>").addClass("wei-overlay is-message-box");
          const $overlayMessageBox = jq("<div></div>").addClass("wei-overlay-message-box");
          const $messageBox = jq("<div></div>").addClass("wei-message-box");
          const $messageBox_header = jq("<div></div>").addClass("wei-message-box__header");
          const $messageBox_content = jq("<div></div>").addClass("wei-message-box__content");
          const $messageBox_btns = jq("<div></div>").addClass("wei-message-box__btns");

          // head
          const $messageBox_title = jq("<div><span>" + title + "</span></div>").addClass("wei-message-box__title");
          const $messageBox_headerbtn = jq("<button type='button'></button>").addClass("wei-message-box__headerbtn").click(() => { $dv.remove(); });
          const $messageBox_headerbtn_close = jq("<i><i/>").addClass("wei-icon wei-message-box__close");
          const $messageBox__headerbtn_close_icon = jq(WEIBW.ICON.close);

          const $messageBox_content_container = jq("<div></div>").addClass("wei-message-box__container");

          // 图标
          if (type) {
            const $messageBox_content_status = jq("<i><i/>").addClass("wei-icon wei-message-box__status wei-message-box-icon--" + type);
            const $messageBox_content_status_icon = jq(WEIBW.ICON[type]);
            $messageBox_content_status_icon.appendTo($messageBox_content_status);
            $messageBox_content_status.appendTo($messageBox_content_container);
          }

          // label
          const $messageBox_content_message = jq("<div><label>" + label + "</label></div>").addClass("wei-message-box__message");

          // input
          const $messageBox_content_input = jq("<div></div>").addClass("wei-message-box__input");
          const $messageBox_content_input_input = jq("<div id='wei_messageBox_prompt_input'></div>").addClass("wei-input");
          const $messageBox_content_input_errormsg = jq("<div id='wei_messageBox_prompt_errormsg'>" + errormsg + "</div>").addClass("wei-message-box__errormsg").hide();
          const $messageBox_content_input_input_wrapper = jq("<div></div>").addClass("wei-input__wrapper");
          const $messageBox_content_input_input_wrapper_inner = jq("<input id='" + iputId + "'/>").addClass("wei-input__inner");


          // 确认按钮
          if (WEIBW._hasProperty(submit, "show", true)) {
            const $messageBox_btns_submit = jq("<button type='button' ><span>" + WEIBW._hasProperty(submit, "text", "提交") + "</span></button>").addClass("wei-button wei-button--" + WEIBW._hasProperty(submit, "type", "primary"))
            $messageBox_btns_submit.click(() => {
              // 点击后首先设置按钮不可用，避免重复点击
              $messageBox_btns_submit.attr('disabled', "true").addClass("is-disabled");
              var promptValue = $("#" + iputId).val();
              const regex = new RegExp(rule);
              if (promptValue !== "" && regex.test(promptValue)) {
                $("#wei_messageBox_prompt_errormsg").hide();
                // 如果有自定义事件，则执行自定义事件，否则默认是关闭窗口
                WEIBW._hasProperty(submit, "clickfunc", false) ? submit["clickfunc"](promptValue) : WEIBW.Feedback.closePrompt(() => {
                  $messageBox_btns_submit.removeAttr("disabled").removeClass("is-disabled");
                });
                WEIBW.Feedback.closePrompt(() => {
                  $messageBox_btns_submit.removeAttr("disabled").removeClass("is-disabled");
                });
              } else {
                $("#wei_messageBox_prompt_errormsg").show();
                $messageBox_btns_submit.removeAttr("disabled").removeClass("is-disabled");
              }
            });
            $messageBox_btns_submit.appendTo($messageBox_btns);
          }

          // 取消按钮
          if (WEIBW._hasProperty(cancel, "show", true)) {
            const $messageBox_btns_cancel = jq("<button type='button' ><span>" + WEIBW._hasProperty(cancel, "text", "取消") + "</span></button>").addClass("wei-button wei-button--" + WEIBW._hasProperty(cancel, "type", "plain"))
            $messageBox_btns_cancel.click(() => {
              // 点击后首先设置按钮不可用，避免重复点击
              $messageBox_btns_cancel.attr('disabled', "true").addClass("is-disabled");
              // 如果有自定义事件，则执行自定义事件，否则默认是关闭窗口
              WEIBW._hasProperty(cancel, "clickfunc", false) ? cancel["clickfunc"]() : WEIBW.Feedback.closePrompt(() => {
                $messageBox_btns_cancel.removeAttr("disabled").removeClass("is-disabled");
              });
              WEIBW.Feedback.closePrompt(() => {
                $messageBox_btns_cancel.removeAttr("disabled").removeClass("is-disabled");
              });
            });
            $messageBox_btns_cancel.appendTo($messageBox_btns);
          }

          // 自定义按钮
          if (custombtns.length > 0) {
            custombtns.forEach(v => {
              const $messageBox_btns_custom = jq("<button type='button' ><span>" + WEIBW._hasProperty(v, "text", "自定义") + "</span></button>").addClass("wei-button wei-button--" + WEIBW._hasProperty(v, "type", "primary"));
              $messageBox_btns_custom.click(() => {
                // 点击后首先设置按钮不可用，避免重复点击
                $messageBox_btns_custom.attr('disabled', "true").addClass("is-disabled");
                // 如果有自定义事件，则执行自定义事件，否则默认是关闭窗口
                WEIBW._hasProperty(v, "clickfunc", false) ? v["clickfunc"]() : WEIBW.Feedback.closePrompt(() => {
                  $messageBox_btns_custom.removeAttr("disabled").removeClass("is-disabled");
                });;
              });
              $messageBox_btns_custom.appendTo($messageBox_btns);
            })
          }


          // 组装元素
          WEIBW._assembleElements({
            node: $dv,
            achild: [
              {
                node: $overlayMessageBox,
                achild: [
                  {
                    node: $messageBox,
                    achild: [
                      {
                        node: $messageBox_header,
                        achild: [
                          { node: $messageBox_title },
                          {
                            node: $messageBox_headerbtn,
                            achild: [
                              {
                                node: $messageBox_headerbtn_close,
                                achild: [
                                  { node: $messageBox__headerbtn_close_icon }
                                ]
                              }
                            ]
                          }
                        ]
                      },
                      {
                        node: $messageBox_content,
                        achild: [
                          {
                            node: $messageBox_content_container,
                            achild: [
                              { node: $messageBox_content_message }
                            ]
                          },
                          {
                            node: $messageBox_content_input,
                            achild: [
                              {
                                node: $messageBox_content_input_input,
                                achild: [
                                  {
                                    node: $messageBox_content_input_input_wrapper,
                                    achild: [
                                      { node: $messageBox_content_input_input_wrapper_inner }
                                    ]
                                  }
                                ]
                              },
                              { node: $messageBox_content_input_errormsg }
                            ]
                          }
                        ]
                      },
                      { node: $messageBox_btns }
                    ]
                  }
                ]
              }
            ]
          })
          $dv.appendTo(jq("body")).on('event', function () { jq("#wei_messageBox_prompt_input").focus(); });
        },


        closePopconfirm: function (bf, af) {
          /**
           * 关闭popconfirm窗口
           * bf，前置事件
           * af，后置事件
           */
          if (bf) { bf() };
          jq("div[id^='wei_popconfirm_']").animate({
            "opacity": 0,
          }, 100, 'linear', () => {
            jq("div[id^='wei_popconfirm_']").remove();
            if (af) { af() };
          });

        },

        popconfirm: function (o) {
          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.popconfirm()"));
            return;
          }
          const [fleft, ftop] = WEIBW._hasProperty(o, "fposition") || [0, 0];
          const [fwidth, fheight] = WEIBW._hasProperty(o, "fsize") || [0, 0];
          const direction = WEIBW._hasProperty(o, "direction") || "bottom";
          const width = WEIBW._hasProperty(o, "width") || "150px";
          const title = WEIBW._hasProperty(o, "title") || "默认title？";
          const submit = WEIBW._hasProperty(o, "submit") || {};
          const cancel = WEIBW._hasProperty(o, "cancel") || {};

          const idStr = "wei_popconfirm_";
          const id = idStr + WEIBW._randomId(8);

          // 移除目前的popconfirm
          jq("div[id^='" + idStr + "']").remove();


          // 定义基础结构
          const $dv = jq("<div id='" + id + "' data-popper-placement='" + direction + "'></div>").addClass("wei-popper is-light wei-popover")
            .css({
              "z-index": 2019,
              "positon": "absolute",
              "inset": "0px auto auto 0px",
              "width": width
            });
          const $popconfirm = jq("<div></div>").addClass("wei-popconfirm");
          const $popconfirm_main = jq("<div>" + title + "</div>").addClass("wei-popconfirm__main");
          const $popconfirm_action = jq("<div></div>").addClass("wei-popconfirm__action");
          const $popconfirm_arrow = jq("<div></div>").addClass("wei-popper__arrow");


          // 确认按钮
          const $popconfirm_action_submit = jq("<button type='button'><span>" + WEIBW._hasProperty(submit, "text", "确认") + "</span></button>").addClass("wei-button wei-button--small wei-button--" + WEIBW._hasProperty(submit, "type", "primary"))
          $popconfirm_action_submit.click(() => {
            // 点击后首先设置按钮不可用，避免重复点击
            $popconfirm_action_submit.attr('disabled', "true").addClass("is-disabled");
            // 如果有自定义事件，则执行自定义事件，否则默认是关闭窗口
            WEIBW._hasProperty(submit, "clickfunc", false) ? submit["clickfunc"]() : WEIBW.Feedback.closePopconfirm(() => {
              $popconfirm_action_submit.removeAttr("disabled").removeClass("is-disabled");
            });
          });

          // 取消按钮
          const $popconfirm_action_cancel = jq("<button type='button'><span>" + WEIBW._hasProperty(cancel, "text", "取消") + "</span></button>").addClass("wei-button wei-button--small wei-button--" + WEIBW._hasProperty(cancel, "type", "plain"))
          $popconfirm_action_cancel.click(() => {
            // 点击后首先设置按钮不可用，避免重复点击
            $popconfirm_action_cancel.attr('disabled', "true").addClass("is-disabled");
            // 如果有自定义事件，则执行自定义事件，否则默认是关闭窗口
            WEIBW._hasProperty(cancel, "clickfunc", false) ? cancel["clickfunc"]() : WEIBW.Feedback.closePopconfirm(() => {
              $popconfirm_action_cancel.removeAttr("disabled").removeClass("is-disabled");
            });
          });

          // 组装元素
          WEIBW._assembleElements({
            node: jq("body"),
            achild: [
              {
                node: $dv,
                achild: [
                  {
                    node: $popconfirm,
                    achild: [
                      { node: $popconfirm_main },
                      {
                        node: $popconfirm_action,
                        achild: [
                          { node: $popconfirm_action_submit },
                          { node: $popconfirm_action_cancel }
                        ]
                      },
                    ]
                  },
                  { node: $popconfirm_arrow }
                ]
              }
            ]
          })


          // 根据出现位置动态计算偏移
          let [x, y, t] = [0, 0, 0];
          const dwidth = width.indexOf('%') != -1 ? (parseFloat(width) * (jq("body").width()) / 100) : WEIBW._px2num(width);
          const dheight = $dv.outerHeight();
          switch (direction) {
            case "left":
              x = parseInt(fleft) - dwidth - 10;
              y = parseInt(ftop) + parseInt(fheight) / 2 - dheight / 2;
              t = {
                "transform": "translate(0," + WEIBW._num2px(-((dheight - 15) / 2)) + ")"
              };
              break;
            case "right":
              x = parseInt(fleft) + parseInt(fwidth) + 10;
              y = parseInt(ftop) + parseInt(fheight) / 2 - dheight / 2;
              t = {
                "transform": "translate(0," + WEIBW._num2px(-((dheight - 15) / 2)) + ")"
              };
              break;
            case "top":
              x = parseInt(fleft) + parseInt(fwidth) / 2 - dwidth / 2;
              y = parseInt(ftop) - dheight - 10;
              t = {
                left: "0px",
                "transform": "translate(" + WEIBW._num2px(((dwidth - 10) / 2)) + ",0)"
              };
              break;
            case "bottom":
              x = parseInt(fleft) + parseInt(fwidth) / 2 - dwidth / 2;
              y = parseInt(ftop) + parseInt(fheight) + 10;
              t = {
                left: "0px",
                "transform": "translate(" + WEIBW._num2px(((dwidth - 10) / 2)) + ",0)"
              };
              break;
          }
          // 因为元素的高度是动态生成的，所以需要在最后确定偏移位置
          $dv.css({ "transform": "translate(" + WEIBW._num2px(x) + "," + WEIBW._num2px(y) + ")" });
          $popconfirm_arrow.css(t);

          jq("window,body,#content-container").scroll(function () {
            $dv.remove();
          });
        },

        closeDialog: function () {
          jq("div[id^='wei_templatedialog_']").remove();
        },

        showTemplateByDialog: function (o) {
          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.showTemplateByDialog()"));
            return;
          }
          const title = WEIBW._hasProperty(o, "title") || "默认标题";
          let url = WEIBW._hasProperty(o, "url") || "https://finereport.weibw162.com";
          const params = WEIBW._hasProperty(o, "params") || {};
          const width = WEIBW._hasProperty(o, "width") || "50%";
          const height = WEIBW._hasProperty(o, "height") || "60%";
          const modalclickclose = WEIBW._hasProperty(o, "modalclickclose") || false;

          // 移除现有的dialog
          WEIBW.Feedback.closeDialog();


          const idStr = "wei_templatedialog_";
          const id = idStr + WEIBW._randomId(8);

          // 定义基础结构
          const $dv = jq("<div id = '" + id + "'></div>").addClass("wei-overlay").css({ "z-index": 2047 }).click(() => { if (modalclickclose) { $dv.remove(); } });
          const $overlayDialog = jq("<div></div>").addClass("wei-overlay-dialog")
          const $dialog = jq("<div></div>").addClass("wei-dialog").css({ "width": width, "height": height });
          const $dialog_header = jq("<header></header>").addClass("wei-dialog__header");
          const $dialog_header_title = jq("<span>" + title + "</span>").addClass("wei-dialog__title");
          const $dialog_header_btn = jq("<button></button>").addClass("wei-dialog__headerbtn").click(() => { $dv.remove(); });;
          const $dialog_header_btn_close = jq("<i><i/>").addClass("wei-icon wei-dialog__close");
          const $dialog_header_btn_close_icon = jq(WEIBW.ICON.close);
          const $dialog_body = jq("<div></div>").addClass("wei-dialog__body");
          const $iframe = $("<iframe  width='100%' height='100%' scrolling='no' frameborder='0'>");

          // 拼接路由
          for (var i in params) {
            let value = params[i] !== undefined ? params[i] : '';
            url += `&${i}=${value}`
          }
          $iframe.attr("src", FR.cjkEncode(encodeURI(url)));

          WEIBW._assembleElements({
            node: jq("body"),
            achild: [
              {
                node: $dv,
                achild: [
                  {
                    node: $overlayDialog,
                    achild: [
                      {
                        node: $dialog,
                        achild: [
                          {
                            node: $dialog_header,
                            achild: [
                              { node: $dialog_header_title },
                              {
                                node: $dialog_header_btn,
                                achild: [
                                  {
                                    node: $dialog_header_btn_close,
                                    achild: [
                                      { node: $dialog_header_btn_close_icon }
                                    ]
                                  }
                                ]
                              }
                            ]
                          },
                          {
                            node: $dialog_body,
                            achild: [
                              { node: $iframe }
                            ]
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          });



        },

        closeDrawer: function () {
          jq("div[id^='wei_templatedrawer_']").remove();
        },

        showTemplateByDrawer: function (o) {

          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.showTemplateByDrawer()"));
            return;
          }
          const title = WEIBW._hasProperty(o, "title") || "默认标题";
          let url = WEIBW._hasProperty(o, "url") || "https://finereport.weibw162.com";
          const params = WEIBW._hasProperty(o, "params") || {};
          const direction = WEIBW._hasProperty(o, "direction") || "right";
          const size = WEIBW._hasProperty(o, "size") || "35%";
          const modalclickclose = WEIBW._hasProperty(o, "modalclickclose") || false;

          // 移除现有的dialog
          WEIBW.Feedback.closeDrawer();


          const idStr = "wei_templatedrawer_";
          const id = idStr + WEIBW._randomId(8);

          // 抽屉展开方向对应class
          const direction_class = {
            "left": "ltr",
            "right": "rtl",
            "top": "ttb",
            "bottom": "btt",
          }

          // 抽屉展开尺寸对应的属性
          const direction_property = {
            "left": "width",
            "right": "width",
            "top": "height",
            "bottom": "height",
          }

          // 定义基础结构
          const $dv = jq("<div id = '" + id + "'></div>").addClass("wei-overlay").css({ "z-index": 2101 }).click(() => { if (modalclickclose) { $dv.remove(); } });
          const $drawer = jq("<div></div>").addClass("wei-drawer").addClass(direction_class[direction]).css({ [direction_property[direction]]: size });
          const $drawer_header = jq("<header></header>").addClass("wei-drawer__header");
          const $drawer_header_title = jq("<span>" + title + "</span>").addClass("wei-drawer__title");
          const $drawer_header_btn = jq("<button type='button'></button>").addClass("wei-drawer__close-btn").click(() => { $dv.remove(); });;
          const $drawer_header_btn_close = jq("<i><i/>").addClass("wei-icon wei-drawer__close");
          const $drawer_header_btn_close_icon = jq(WEIBW.ICON.close);
          const $drawer_body = jq("<div></div>").addClass("wei-drawer__body");
          const $iframe = $("<iframe  width='100%' height='100%' scrolling='no' frameborder='0'>");

          // 拼接路由
          for (var i in params) {
            let value = params[i] !== undefined ? params[i] : '';
            url += `&${i}=${value}`
          }
          $iframe.attr("src", FR.cjkEncode(encodeURI(url)));

          // 组装元素
          WEIBW._assembleElements({
            node: jq("body"),
            achild: [
              {
                node: $dv,
                achild: [
                  {
                    node: $drawer,
                    achild: [
                      {
                        node: $drawer_header,
                        achild: [
                          { node: $drawer_header_title },
                          {
                            node: $drawer_header_btn, achild: [
                              {
                                node: $drawer_header_btn_close,
                                achild: [
                                  { node: $drawer_header_btn_close_icon }
                                ]
                              }
                            ]
                          }
                        ]
                      },
                      {
                        node: $drawer_body,
                        achild: [
                          { node: $iframe }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          })





        },
        closePopover: function () {
          jq("div[id^='wei_templatepopover_']").remove();
        },

        showTemplateByPopover: function (o) {
          if (WEIBW._isNull(o)) {
            WEIBW.throw(WEIBW.ERROR.E10001("WEIBW.Feedback.showTemplateByPopover()"));
            return;
          }
          const [fleft, ftop] = WEIBW._hasProperty(o, "fposition") || [0, 0];
          const [fwidth, fheight] = WEIBW._hasProperty(o, "fsize") || [0, 0];

          let url = WEIBW._hasProperty(o, "url") || "https://finereport.weibw162.com";
          const params = WEIBW._hasProperty(o, "params") || {};
          const direction = WEIBW._hasProperty(o, "direction") || "right";
          const width = WEIBW._hasProperty(o, "width") || "30%";
          const height = WEIBW._hasProperty(o, "height") || "30%";

          // 移除现有的dialog
          WEIBW.Feedback.closePopover();


          const idStr = "wei_templatepopover_";
          const id = idStr + WEIBW._randomId(8);

          // 根据出现位置动态计算偏移
          let [x, y, t] = [0, 0, 0];
          const dwidth = width.indexOf('%') != -1 ? (parseFloat(width) * (jq("body").width()) / 100) : WEIBW._px2num(width);
          const dheight = height.indexOf('%') != -1 ? (parseFloat(height) * (jq("body").height()) / 100) : WEIBW._px2num(height);

          switch (direction) {
            case "left":
              x = parseInt(fleft) - dwidth - 10;
              y = parseInt(ftop) + parseInt(fheight) / 2 - dheight / 2;
              t = "translate(0," + WEIBW._num2px((dheight - 30) / 2) + ")";
              break;
            case "right":
              x = parseInt(fleft) + parseInt(fwidth) + 10;
              y = parseInt(ftop) + parseInt(fheight) / 2 - dheight / 2;
              t = "translate(0," + WEIBW._num2px((dheight - 30) / 2) + ")";
              break;
            case "top":
              x = parseInt(fleft) + parseInt(fwidth) / 2 - dwidth / 2;
              y = parseInt(ftop) - dheight - 10;
              t = "translate(" + WEIBW._num2px(-((dwidth - 30) / 2)) + ",0)";
              break;
            case "bottom":
              x = parseInt(fleft) + parseInt(fwidth) / 2 - dwidth / 2;
              y = parseInt(ftop) + parseInt(fheight) + 10;
              t = "translate(" + WEIBW._num2px(-((dwidth - 30) / 2)) + ",0)";
              break;
          }

          const $dv = jq("<div data-popper-placement='" + direction + "' id='" + id + "'></div>").addClass("wei-popper is-light wei-popover").css({
            "z-index": 2178,
            "positon": "absolute",
            "inset": "0px auto auto 0px",
            "width": width,
            "height": height,
            "transform": "translate(" + WEIBW._num2px(x) + "," + WEIBW._num2px(y) + ")"
          }).mouseleave(() => { $dv.remove() });

          const $popover_arrow = jq("<span></span>").addClass("wei-popper__arrow").css({
            "position": "absolute",
            "transform": t
          });

          const $iframe = $("<iframe  width='100%' height='100%' scrolling='no' frameborder='0'>");

          // 拼接路由
          for (var i in params) {
            let value = params[i] !== undefined ? params[i] : '';
            url += `&${i}=${value}`
          }
          $iframe.attr("src", FR.cjkEncode(encodeURI(url)));

          // 组装元素
          WEIBW._assembleElements({
            node: jq("body"),
            achild: [
              {
                node: $dv,
                achild: [
                  { node: $iframe },
                  { node: $popover_arrow }
                ]
              }
            ]
          })

          // 屏幕滚动则销毁元素
          jq("window,body,#content-container").scroll(function () {
            $dv.remove();
          });
          // 给body添加点击事件，点击后销毁元素
          setTimeout(function () {
            jq("body").click({ name: 'closePopover' }, () => { $dv.remove(); jq("body").off("click.closePopover"); })
          }, 100);



        }

      }
    }()
  })
})(jQuery);
